/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package mathma.core.form;

import mathma.core.expr.Expression;

import mathma.core.value.Value;

/**
 * @since 0.2.2
 * @author Ethan Levine
 */
public class UnaryWrappedExpression<E extends Value, O extends Value>
        extends UnaryExpression<E, O> {

    private final FormulaicExpression<E, O> backingExpr;

    private final int visibleOperand;

    public UnaryWrappedExpression(FormulaicExpression<E, O> backingExpr,
            int visibleOperand) {
        super(backingExpr.getType(), backingExpr.getOperands().get(visibleOperand));
        this.backingExpr = backingExpr;
        this.visibleOperand = visibleOperand;
    }

    public E evaluate() {
        return backingExpr.evaluate();
    }

    public FormulaicExpression<E, O> getBackingExpr() {
        return backingExpr;
    }

    @Override
    public UnaryExpression<E, O> newUnaryExpression(Expression<O> operand) {
        // TODO - patch up.
        return new UnaryWrappedExpression(backingExpr, visibleOperand);
    }
}
